package com.z1.core.utils;

import com.z1.core.exception.Z1Exception;

public class QidUtils {
	
	public static String generateQid(String prefix, String id) {
		if (null == prefix) { throw new Z1Exception("前缀为空."); }
		if (null == id) { throw new Z1Exception("编号为空."); }
		return new StringBuffer(prefix)
			.append(UtilsConst.ID_SEPARATOR)
			.append(id)
			.toString();
	}
	
	public static String getIdByQid(String prefix, String qid) {
		if (null == prefix) { throw new Z1Exception("前缀为空."); }
		if (null == qid) { throw new Z1Exception("编号为空."); }
		if (qid.length() > prefix.length() + 1) { return qid.substring(prefix.length() + 1); }
		else { return null; }
	}
	
	public static String generateRelationQid(String dealer, String...ids) {
		if (null == dealer) { throw new Z1Exception("所属经销商为空."); }
		StringBuffer buffer = new StringBuffer(dealer);
		if (null != ids) {
			for (String id : ids) {
				if (null != id && !id.trim().equals("")) {
					buffer.append(UtilsConst.ID_SEPARATOR)
						.append(id);
				}
			}
		}
		return buffer.toString(); 
	}
	
}
